import syscall
import package.zlib_temp

var input = 'mock/input.txt'
var output = 'output.gz'

var fd = syscall.open(input, syscall.O_RDONLY, 0666)

var gzfile = gzopen(output.ref(), 'wb'.ref())

var buf = vec<u8>{len=4096}
for true {
    var len = syscall.read(fd, buf)
    if len == 0 {
        break
    }

    // gzwrite
    int write_len = gzwrite(gzfile, buf.ref(), len)
    if write_len != len {
        syscall.close(fd)
        gzclose(gzfile)

        throw 'write failed'
    }

    println('gz write success, len:', write_len)
}

syscall.close(fd)
gzclose(gzfile)

println('gz success full')